package com.agou.app.admin.business.menu.bo;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import com.agou.app.admin.business.menu.vo.AdminMenuVo;
import com.agou.app.admin.dbconfig.bean.TSAdminMenuNavi;
import com.agou.app.admin.dbconfig.bean.VSAdminMenuNavi;
import com.agou.core.enums.EnTreeNodeType;
import com.agou.core.ss.SSException;
import com.agou.core.ss.SSTrace;
import com.agou.ssh.core.base.BOResultSet;
import com.agou.ssh.web.tree.JqueryTree;
import com.agou.ssh.web.tree.TreeNode;

public class AdminMenuBo extends IAdminMenuBo {

	private static SSTrace ssTrace = SSTrace.getInstance(AdminMenuBo.class);

	// 查询菜单信息
	public BOResultSet queryMenu(AdminMenuVo menuVo) throws SSException,
			SQLException, IOException {
		ssTrace.debug("queryMenu", "查询菜单信息：#0", menuVo);
		BOResultSet boResult = new BOResultSet(this.getClass());
		this.getAdminMenuDao().setJdbcSession(this.getJdbcSession());// 设置数据库环境
		
		List<VSAdminMenuNavi> menuList = this.getAdminMenuDao().queryMenu(menuVo.getNaviId());//
		boResult.addDataMap("menu_list", menuList);//-------
		JqueryTree jqueryTree = new JqueryTree();
		VSAdminMenuNavi tvo ;
		for(int i = 0 ; i < menuList.size() ; i++){
			tvo = menuList.get(i);
			TreeNode treeNode = new TreeNode();
			treeNode.id = String.valueOf(tvo.menuId);
			treeNode.name = tvo.menuName;
			treeNode.url = tvo.menuUrl;
			treeNode.pid = String.valueOf(tvo.pmenuId);
			treeNode.type = EnTreeNodeType.getEnum(tvo.getMenuType());
			treeNode.dataOption = tvo.getDataOptions();
			jqueryTree.addTreeNode(treeNode);
		}
		jqueryTree.endAdd();//结束添加
		boResult.addDataMap("tree_html", jqueryTree.generationHtml());

		TSAdminMenuNavi naviInfo = this.getAdminMenuDao().queryMenuNavi(menuVo.getNaviId());
		boResult.addDataMap("navi_info", naviInfo);//-------
		
		return boResult;
	}

	public BOResultSet queryMenuNavi(AdminMenuVo menuVo) throws SSException,
			SQLException, IOException {
		ssTrace.debug("queryMenu", "查询导航信息：#0", this.getJdbcSession());
		BOResultSet boResult = new BOResultSet(this.getClass());
		this.getAdminMenuDao().setJdbcSession(this.getJdbcSession());// 设置数据库环境
		List<TSAdminMenuNavi> naviList = this.getAdminMenuDao().queryMenuNavi();//
		//List<TSAdminMenuNavi> commNaviList = this.getAdminMenuDao().queryMenuNavi(EnAdminNavigationType.Commonality);//
		//List<TSAdminMenuNavi> pageNaviList = this.getAdminMenuDao().queryMenuNavi(EnAdminNavigationType.Page);//
		//区分导航 和 公共 及 其它的list
		boResult.addDataMap("navi_list", naviList);
		return boResult;
	}
}
